#include "namedPipe.hpp"

// serve read 管理命名管道的生命周期
int main()
{
    perror("111111111");
    std::cerr << "22222222222" << std::endl;
    NamedPipe fifo(comm_path, Creater);
    if (fifo.OpenForRead()) // 打开成功
    {
        while (true)
        {
            std::string str1;
            int n = fifo.ReadNamedPipe(&str1); // 输出型参数
            if (n > 0)
            {
                std::cout << "read success, message is > " << str1 << std::endl;
            }
            else if (n == 0)
            {
                std::cout << "write quit, read too!" << std::endl;
                break;
            }
            else //(n < 0)
            {
                std::cerr << "read fail" << std::endl;
                break;
            }
            // std::cout << str1 << std::endl;
        }
    }

    return 0;
}